<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>优车管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
    <style type="text/css">
        .searchArea .fieldBox .label {
            width: 70px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <!-- 页签1：优车管理 -->
        <div tabid="tabA" title="优车管理" lselected="true">
            <div class="searchArea">
                <!-- 搜索表单开始 -->
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="FXBR">
                            <div class="fieldBox">
                                <div class="label">客户名称</div>
                                <div class="field">
                                    <input type="text" id="cstNm" name="cstNm" class="ui-textbox" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">支付表号</div>
                                <div class="field">
                                    <input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">处置状态</div>
                                <div class="field">
                                    <select name="dealStsCd" id="dealStsCd">
                                        <option value=" " selected>请选择</option>
                                        <c:forEach items="${dealStsList }" var="deal">
                                            <c:if test="${deal.key == '11' || deal.key == '13' || deal.key == '14' || deal.key == '15' }">
                                                <option value="${deal.key }">${deal.value }</option>
                                            </c:if>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">评估状态</div>
                                <div class="field">
                                    <select name="evalStatusCd" id="evalStatusCd">
                                        <option value=" " selected>请选择</option>
                                        <c:forEach items="${evalStsList }" var="eval">
                                            <option value="${eval.key }">${eval.value }</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">是否可过户</div>
                                <div class="field">
                                    <select name="isAssign" id="isAssign">
                                        <option value=" " selected>请选择</option>
                                        <option value="1">是</option>
                                        <option value="0">否</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">入库状态</div>
                                <div class="field">
                                    <select name="isEnter" id="isEnter">
                                        <option value=" " selected>请选择</option>
                                        <option value="0">未入库</option>
                                        <option value="1">已入库</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">出库状态</div>
                                <div class="field">
                                    <select name="isOut" id="isOut">
                                        <option value=" " selected>请选择</option>
                                        <option value="0">未出库</option>
                                        <option value="1">已出库</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">拍卖状态</div>
                                <div class="field">
                                    <input name="auctionStsCd" id="auctionStsCd" data-value="" placeholder="请选择" ltype="combobox"/>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">到账状态</div>
                                <div class="field">
                                    <input name="toAccStsCd" id="toAccStsCd" data-value="" placeholder="请选择" ltype="combobox"/>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">诉讼状态</div>
                                <div class="field">
                                    <input name="sueStsCd" id="sueStsCd" data-value="" placeholder="请选择" ltype="combobox"/>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">入库时间</div>
                                <div class="field">
                                    <input type="text" id="minEnterTm" name="minEnterTm" class="ui-datepicker" value="" ligerui="width: 88"/>
                                    -
                                    <input type="text" id="maxEnterTm" name="maxEnterTm" class="ui-datepicker" value="" ligerui="width: 88"/>
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">出库时间</div>
                                <div class="field">
                                    <input type="text" id="minOutTm" name="minOutTm" class="ui-datepicker" value="" ligerui="width: 88"/>
                                    -
                                    <input type="text" id="maxOutTm" name="maxOutTm" class="ui-datepicker" value="" ligerui="width: 88"/>
                                </div>
                            </div>
                        </div>
                        <!-- 隐藏当前选中的拖车主表ID和明细表ID信息 -->
                        <div class="fieldBox" style="display:none;">
                            <div class="field">
                                <input name="tcMasterId" id="tcMasterId" type="text" class="ui-textbox" value="${tcMasterId}">
                                <input name="tcDetailId" id="tcDetailId" type="text" class="ui-textbox" value="${tcDetailId}">
                            </div>
                        </div>

                        <div class="clearFix"></div>

                        <!-- 表单按钮 -->
                        <div class="btnsBox formBtns notRight">
                            <span id="searchBtn" class="sq-button-round">查询</span>
                            <span id="clearBtn" class="sq-button-round">清空</span>
                            <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            <%--<span id="downBtn" class="sq-button-round" onclick="downloadBtnEvent();">导出Excel</span>--%>
                            <span id="dealCarBtn" class="sq-button-round" onclick="yc_dealCar();">优车处置</span>
                        </div>
                    </div>
                </form>
                <!-- 搜索表单结束 -->
            </div>
            <!-- 列表显示块 -->
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <!-- 页签2：流程跟踪 -->
        <div tabid="tabB" title="流程跟踪" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
        <sys:funcAuth resCd="ass_zyc_manage">
            <!-- 页签3：转优车管理 -->
            <div tabid="tabC" title="转优车管理" id="tabCId">
                <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
            </div>
        </sys:funcAuth>
    </div>
</div>
<script type="text/javascript">
    var pageInApp = {
        flag: false //tab页验证关闭
    };//to下一级子窗口 接口
    var pageInTab = null;//页签
    var grid = null;
    $(function () {
        initForm();//初始化表单
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        initTab();//初始化页签
        searchBtnEvent();//查询按钮事件
        clearBtnEvent();//清空按钮事件
    });

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();

        //拍卖状态
        $("#auctionStsCd").ligerComboBox({valueField: 'key', textField: 'value'});
        liger.get("auctionStsCd").setData(${auctionStsList});

        //到账状态
        $("#toAccStsCd").ligerComboBox({valueField: 'key', textField: 'value'});
        liger.get("toAccStsCd").setData(${toAccStsList});

        //到账状态
        $("#sueStsCd").ligerComboBox({valueField: 'key', textField: 'value'});
        liger.get("sueStsCd").setData(${lawsuitStsList});
    }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/ass/assTrailCarM/optimalInitList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {
                    display: '支付表号', name: 'paySchNo', minWidth: 180, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        h = '<a href="javascript:payDetail(';
                        h += "'" + rowdata.prjPrdDtlId + "',"; //项目产品明细信息表ID
                        h += "'" + rowdata.paySchId + "',"; //支付表ID
                        h += "'" + rowdata.prjPrdId + "',"; //项目产品基础信息表ID
                        h += "'" + rowdata.prjId + "'"; //项目基础信息表ID
                        h += ')">' + value + '</a>';
                        return h;
                    }
                },
                {display: '客户名称', name: 'cstNm', width: 120, enabledSort: true},
                {display: '拖车状态', name: 'backStsCd', width: 80, align: 'center', enabledSort: true},
                {display: '诉讼状态', name: 'sueStsNm', width: 80, align: 'center', enabledSort: true},
                {display: '租赁物件名称', name: 'prdNm', width: 80, enabledSort: true},
                {display: '型号', name: 'prdMdl', width: 100, align: 'center', enabledSort: true},
                {display: '车架号', name: 'prdVin', width: 100, align: 'center', enabledSort: true},
                {display: '处置状态', name: 'dealStsCd', width: 100, align: 'center', enabledSort: true},
                {display: '车源编号', name: 'carSrcNo', width: 100, align: 'center', enabledSort: true},
                {
                    display: '处置费用', name: 'dealAmt', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = rowdata.dealAmt / 100;
                        return h;
                    }
                },
                {display: '评估状态', name: 'evalStatusCd', width: 100, align: 'center', enabledSort: true},
                {
                    display: '入库时间', name: 'enterTm', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (rowdata.isEnter == "1") {
                            h = renderDate1(rowdata.enterTm);
                        } else {
                            h = '未入库';
                        }
                        return h;
                    }
                },
                {
                    display: '出库时间', name: 'outTm', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (rowdata.isOut == "1") {
                            h = renderDate1(rowdata.outTm);
                        } else {
                            h = '未出库';
                        }
                        return h;
                    }
                },
                {
                    display: '是否可过户', name: 'isAssign', width: 100, align: '', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (rowdata.isAssign == "1") {
                            h = "是";
                        } else if (rowdata.isAssign == "0") {
                            h = "否";
                        }
                        return h;
                    }
                },
                {
                    display: '转优车时间', name: 'dealTm', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = renderDate1(rowdata.dealTm);
                        return h;
                    }
                },
                { display: '拍卖状态', name: 'auctionStsCdNm', width: 100, align: 'center', enabledSort: true},
                { display: '到账状态', name: 'toAccStsCdNm', width: 100, align: 'center', enabledSort: true}
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: false,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,//列表是否有选择框
            rownumbers: true,//列表是否有行号
            //选择行事件
            onSelectRow: function (rowdata, rowid, rowobj) {
                //设置当前选择的拖车主表ID和明细表ID值
                $("#tcDetailId").val(rowdata.detailId);
                $("#tcMasterId").val(rowdata.masterId);
            },
            //取消选择行事件
            onUnSelectRow: function (rowdata, rowid, rowobj) {
                //清空当前选择的拖车主表ID和明细表ID值
                $("#tcDetailId").val('');
                $("#tcMasterId").val('');
            }
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        grid.options.isSingleCheck = true;//列表是否为单选
    }

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                //获取拖车主表ID和明细表ID供其它页面使用
                var tcDetailId = $("#tcDetailId").val();
                var tcMasterId = $("#tcMasterId").val();
                if (tabid == "tabB") {
                    if (!tcDetailId || !tcMasterId) {
                        $.ligerDialog.SQalert({content: "请选择一条信息！", SQ_type: "warning"});
                        return false; //验证不通过，不执行以下代码
                    }
                }
                switch (tabid) {
                    case "tabB":
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/assTrailCarM/toFlowPage.do?tcMasterId=" + tcMasterId + "&tcDetailId=" + tcDetailId);
                        break;
                    case "tabC":
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/dealcar/manage/toListPage.do");
                        break;
                }
                SetIframe_height();
            }
        });
        //设置页签
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    };

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "dealStsCd": " ",
                "evalStatusCd": " ",
                "isEnter": " ",
                "isOut": " "
            });
            $("input[type='hidden'][id$='Cd_val']").val("");
        });
    }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });
    }

    //查看支付表详情
    function payDetail(prjPrdDtlId, id, prjPrdId, prjId) {
        var editFlag = true;
        Add_navTab('tab_prj_quat_prps' + id, '查看支付表', '<%=path%>/project/prjprdpayschm/toAddPage.do?prjId=' + prjId + '&&id=' + id + '&&prjPrdDtlId=' + prjPrdDtlId + '&&prjPrdId=' + prjPrdId + '&&detailFlag=' + editFlag);
    }

    //拖车申请
    function trailCarApply(paySchId, paySchNo) {
        Add_navTab('trailCar' + paySchId, '拖车申请', '<%=path%>/ass/assTrailCarD/toApplyPage.do?paySchId=' + paySchId + '&&paySchNo=' + paySchNo);
    }

    //显示流程：流程实例ID,状态,业务主键(拖车主表ID)
    function commShowFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/ass/assTrailCarM/toViewPage.do?isDetail=1@@tcMasterId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //优车处置
    function yc_dealCar() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        // 校验诉讼状态可否发起优车处置
        var sueStsCd = selectedRows[0].sueStsCd;// 诉讼状态
        if (!(StringUtils.isEmpty(sueStsCd) || '0000' == sueStsCd
            || '0003' == sueStsCd || '0006' == sueStsCd)) {
            $.ligerDialog.SQalert({content: selectedRows[0].sueStsNm + "状态无法发起优车处置流程！", SQ_type: "warning"});
            return;
        }

        var url = '<%=path%>/ass/assTrailCarM/toYCDealApplyPage.do';
        var tcMasterId = selectedRows[0].masterId;//拖车主表ID
        var tcDetailId = selectedRows[0].detailId;//拖车明细ID
        var optimal_Id = selectedRows[0].id;//转优车表ID
        var prjPrdDtlId = selectedRows[0].prjPrdDtlId;//项目产品明细表ID
        var prjId = selectedRows[0].prjId;//项目表ID
        var cstId = selectedRows[0].cstId;//客户ID
        var cstNm = selectedRows[0].cstNm;//客户名称
        var orgName = selectedRows[0].orgName;//事业部名称
        var buOrgCd = selectedRows[0].orgSimpleCode;//事业部简称
        var backedFlagCd = selectedRows[0].backedFlagCd;//拖回标记(ASS0014)
        var businessType = selectedRows[0].businessType;//业务类型
        var prjTypCd = selectedRows[0].prjTypCd;//项目类型
        var prjNm = selectedRows[0].prjNm;//项目名称
        var sueApplyId = selectedRows[0].sueApplyId;
        sueApplyId = sueApplyId == null ? "" : sueApplyId;
        var auctionStsCdNm = selectedRows[0].auctionStsCdNm;
        auctionStsCdNm = auctionStsCdNm == null ? "" : auctionStsCdNm;

        var param = '?tcMasterId=' + tcMasterId + '&tcDetailId=' + tcDetailId + '&optimal_Id=' + optimal_Id;
        param += '&backedFlagCd=' + backedFlagCd + '&cstId=' + cstId + '&cstNm=' + cstNm + '&prjId=' + prjId;
        param += '&buOrgCd=' + buOrgCd + '&orgName=' + orgName + '&prjPrdDtlId=' + prjPrdDtlId;
        param += '&&prjTypCd=' + prjTypCd + '&&prjNm=' + prjNm + '&&businessType=' + businessType + "&sueApplyId=" + sueApplyId + "&auctionStsCdNm=" + auctionStsCdNm;
        //回调刷新列表
        var callback = function () {
            grid.reload();
        };
        Add_navTab("optimalCar" + tcDetailId, "优车处置", url + param, callback);
    }

    //导出信息
    function downloadBtnEvent() {
        var form = new liger.get("searchBar");
        var grid = liger.get("ligergrid1");
        var selectedRows = grid.getSelectedRows();
        var pkIds = new Array();
        for (var i = 0; i < selectedRows.length; i++) {
            var pkId = "'" + selectedRows[i].paySchId + "'";
            pkIds[i] = pkId;
        }
        var data = form.getData();
        data["pkIds"] = JSON.stringify(pkIds);
        data["eFlag"] = "ycgl";
        var wait_dialog = null;
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/ass/assTrailCarM/exportAssInfo.do',
            data: data,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: '正在导出信息...', SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    window.open(msg.data);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
</script>
</body>
</html>